836 - Largest submatrix (DP, programación dinámica, O(n^4) ¿Existirá un O(n^3)?)
[andmenj-acm.git] / 10036 - Divisibility / 10036.2.cpp
blob0da2be69946861616d5385827a786a2201fde884
1 /*
2 Accepted
3 */
4 #include <iostream>
6 using namespace std;
8 const int MAXN = 10000, MAXK = 100;
10 bool dp[MAXN][MAXK];
11 int a[MAXN];
13 int main(){
14 int cases;
15 cin >> cases;
16 while (cases--){
17 int n, k;
18 cin >> n >> k;
19 if ( (0 <= n && n <= MAXN && 0 <= k && k <= MAXK) == false ) while (1);
20 for (int i=0; i<n; ++i){
21 cin >> a[i];
24 for (int j=0; j<k; ++j){
25 dp[0][j] = false;
28 int t = a[0];
29 while (t < 0) t += k;
30 dp[0][t%k] = true;
31 for (int i=1; i<n; ++i){
32 for (int j=0; j<k; ++j){
33 dp[i][j] = false;
34 t = j + a[i];
35 while (t < 0) t += k;
36 dp[i][j] |= dp[i-1][t%k];
38 t = j - a[i];
39 while (t < 0) t += k;
40 dp[i][j] |= dp[i-1][t%k];
44 cout << (dp[n-1][0]?"D":"Not d") << "ivisible" << endl;
46 return 0;